package javase.spring.util;

import com.sun.deploy.util.StringUtils;

import java.io.File;
import java.util.List;
import java.util.Locale;

public class FileUtil {

    public static List<String> readFile(String dir , List<String> fileList){
        File file = new File(dir);
        if (file.exists()){
            File[] files = file.listFiles();
            for (File f:files
                 ) {
                if (f.isDirectory()){
                    readFile(f.getAbsolutePath(),fileList);
                }
                if(f.isFile()){
                    String className = coverClassName(f.getAbsolutePath());
                    fileList.add(className);

                }
            }
        }

    return  fileList;


    }

    public  static String coverClassName(String filePath) {
        ///    /C:/Users/Administrator/IdeaProjects/kuangjia/out/production/spring1/
        filePath = filePath.substring(filePath.indexOf("spring1")+8,filePath.length()-6);


        return filePath.replaceAll("\\\\",".");
    }

    public static  String toFirstCharToLowerChar(String name){
       if (Character.isLowerCase(name.charAt(0))){
           return name;
       }else {
           return (""+name.charAt(0)).toLowerCase()+name.substring(1);
       }

    }

    public static  String coverBeanName(String className){

        String beanName= className.substring(className.lastIndexOf(".")+1);
        return toFirstCharToLowerChar(beanName);
    }

}
